var http = require("http");

function sendHttpRequest(host, port, route, params = '', headers = {}, encoding = 'utf8') {
    let params_str = '';
    for (let key in params) {
        params_str += key + '=' + params[key] + '&';
    }
    params_str = '?' + params_str;

    let options = {
        hostname: host,
        port: port,
        path: '/' + route + params_str,
        method: 'GET',
        headers: headers
    };

    let data = '';
    return new Promise(function (resolve, reject) {
        let req = http.request(options, function (res) {
            res.setEncoding(encoding);
            res.on('data', function (chunk) {
                data += chunk;
            });

            res.on('end', function () {
                resolve({
                    result: true,
                    data: data
                });
            });
        });

        req.on('error', (e) => {
            resolve({
                result: false,
                errmsg: e.message
            });
        });
        req.end();
    });
}

// 请求例子
let res = sendHttpRequest('www.wufazhuce.com', 80, '', {});



hexo.extend.helper.register('getOne', function (path) {
    var oneObj={text:'她美丽得恍若梦幻。那是一种此前见所未见甚至想所未想的美丽。一切如宇宙一般膨胀开来，同时又全部凝缩在厚实的冰河里。一切被夸张得近乎傲慢，同时又全部被削落殆尽。',
    img:'http://image.wufazhuce.com/FlLlpA6GBJ20Rr8NTllgHHdgWnfz'};
    return oneObj;
});